package com.totoro.domain;

import java.sql.Date;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * 定义通知实体类
 */
@Entity
@Table(name = "notice")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Notice extends BaseDomain {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;// 主键

	// 级联更新
	@ManyToOne(cascade = { CascadeType.ALL })
	@JoinColumn(name = "tutor_id")
	private Tutor tutor;// 关联员工类

	// 集合映射
	@ElementCollection(fetch = FetchType.EAGER,targetClass = com.totoro.domain.Attachment.class)
	@CollectionTable(name = "notice_attachment", joinColumns = @JoinColumn(name = "notice_id"))
	private Collection<Attachment> attachment;// 附件

	/*
	 * 1.一对多要添加mappedBy映射， 2.FetchType.EAGER：急加载，加载一个实体时，定义急加载的属性会立即从数据库中加载
	 */
	@OneToMany(mappedBy = "notice", fetch = FetchType.LAZY)
	private Collection<NoticeRole> noticeRole;// 关联NoticeRole类

	private Date createdDate;// 创建时间

	private String title;// 题目

	private String body;// 内容

	@ManyToOne
	@JoinColumn(name = "tutorRole_id")
	private Role role;// 发通知关联的角色

	// 构造空的构造器
	public Notice() {
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Tutor getTutor() {
		return tutor;
	}

	public void setTutor(Tutor tutor) {
		this.tutor = tutor;
	}

	public Collection<Attachment> getAttachment() {
		return attachment;
	}

	public void setAttachment(Collection<Attachment> attachment) {
		this.attachment = attachment;
	}

	public Collection<NoticeRole> getNoticeRole() {
		return noticeRole;
	}

	public void setNoticeRole(Collection<NoticeRole> noticeRole) {
		this.noticeRole = noticeRole;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

}